package com.ssm.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ssm.pojo.Company;
import com.ssm.pojo.Employment;
import com.ssm.pojo.Person;
import com.ssm.pojo.Position;
import com.ssm.service.CompanyService;
import com.ssm.service.EmploymentService;
import com.ssm.service.InfoService;
import com.ssm.service.PersonService;
import com.ssm.service.PositionService;

@Controller
@RequestMapping("/show")
public class ShowController {
	@Resource
	private PositionService positionServiceImpl;
	@Resource
	private InfoService infoServiceImpl;
	@Resource
	private CompanyService companyServiceImpl;
	@Resource
	private PersonService personServiceImpl;
	@Resource
	private EmploymentService employmentServiceImpl;
	/**
	 * 显示职位类表 /*
     * 列表与分页Action
	 * @return
	 */
	
	
	@RequestMapping(value = "/showposition")
	public String showposition(Model model,@RequestParam(required=false,defaultValue="1") int pageNO){
//		List<Position> positions = positionServiceImpl.selall();
//		req.setAttribute("positions", positions);
		  	int size=5;
		//	System.out.println("进来了");
	        model.addAttribute("size",size);
	        model.addAttribute("pageNO",pageNO);
//	        System.out.println(size+pageNO);
	        model.addAttribute("count",positionServiceImpl.getPositionCount());
	        model.addAttribute("positions", positionServiceImpl.getPositionPager(pageNO, size));
	       return "person/position";
	}
	
	
	@RequestMapping(value = "/showinfo")
	public String showinfo(Model model,@RequestParam(required=false,defaultValue="1") int pageNO){
//		List<Position> positions = positionServiceImpl.selall();
//		req.setAttribute("positions", positions);
		
		  	int size=5;
	        model.addAttribute("size",size);
	        model.addAttribute("pageNO",pageNO);

			//	        System.out.println(size+pageNO);
	        model.addAttribute("count",infoServiceImpl.getInfoCount());
	        model.addAttribute("infos", infoServiceImpl.getInfoPager(pageNO, size));
	        return "company/info";
	}
	
	
	
	@RequestMapping(value = "/showmyinfo")
	public String showmyinfo(int pId, Model model,@RequestParam(required=false,defaultValue="1") int pageNO){
//		List<Position> positions = positionServiceImpl.selall();
//		req.setAttribute("positions", positions);
		  	int size=5;
	        model.addAttribute("size",size);
	//        System.out.println(pageNO);
	        model.addAttribute("pageNO",pageNO);

			//	        System.out.println(size+pageNO);
	        model.addAttribute("count",infoServiceImpl.getmyInfoCount(pId));
	        model.addAttribute("infos", infoServiceImpl.getmyInfoPager(pId, pageNO, size));
	        return "person/showmyinfo";
	}
	
	
	/**
	 * 显示公司信息
	 * @param id
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/showcompany")
	public String showCompany(int id ,HttpServletRequest req){
		Company company = companyServiceImpl.selectbyid(id);
		req.setAttribute("company", company);
		return "company/showcompanyinfo";
		
		
		
	}
	/**
	 * 显示求职者信息
	 * @param id
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/showperson")
	public String showperson(int id ,HttpServletRequest req){
		Person person = personServiceImpl.selectbyid(id);
		req.setAttribute("person", person);
		return "person/showpersoninfo";
	}
	/**
	 * 显示公司发布的职位信息
	 * @param model
	 * @param pageNO
	 * @return
	 */
	@RequestMapping(value = "/showmyposition")
	public String showmyposition(int cId,Model model,@RequestParam(required=false,defaultValue="1") int pageNO){
//		List<Position> positions = positionServiceImpl.selall();
//		req.setAttribute("positions", positions);
		  	int size=5;
		  
	        model.addAttribute("size",size);
	        model.addAttribute("pageNO",pageNO);
//	        System.out.println(size+pageNO);
	        model.addAttribute("count",positionServiceImpl.getmyPositionCount(cId));
	        model.addAttribute("positions", positionServiceImpl.getmyPositionPager(pageNO, size, cId));
	       return "company/myposition";
	}
	
	@RequestMapping(value = "/showpersonposition")
	public String showpersonposition(int cId,HttpServletRequest req){
		List<Employment> lists = employmentServiceImpl.selbycid(cId);
		req.getSession().setAttribute("lists", lists);
		return "company/showpersonposition" ;
		
	}
	


}
